﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using MyGeneration.dOOdads;
using MethodIT.Helper;

using Hr20.DAL;
using Hr20.BLL;
using Hr20.ProcessFlow;

namespace Appraisal.Web.ZB
{
    public partial class ZbFromPrice : System.Web.UI.Page
    {
        private const string HTML_SPACE = "&nbsp;";
        private const string ITEM_CTRL_PREID = "KPItem_";

        protected void Page_Load(object sender, EventArgs e)
        {
            btnPrintTop.Attributes.Add("onclick", "excel(phTemplate);");
            btnPrintBottom.Attributes.Add("onclick", "excel(phTemplate);");

            int nSubID = HelperURL.GetIntFromUrlString("SubID");
            int nKpID = HelperURL.GetIntFromUrlString("KpID");
            int nUmpID = HelperURL.GetIntFromUrlString("UmpID");
            int nDisplay = HelperURL.GetIntFromUrlString("Display");
            bool Display = nDisplay.Equals(1);

            DisplayRating(nSubID, nKpID, nUmpID, Display);
        }

        // 评分
        private void DisplayRating(int nSubID, int nKpID, int nUmpID, bool Display)
        {
            VW_ZB_ItemResult itemResult = new VW_ZB_ItemResult();
            itemResult.Where.KpID.Value = nKpID;
            itemResult.Where.UmpID.Value = nUmpID;
            itemResult.Where.SubID.Value = nSubID;
            itemResult.Query.Load();

            KP_Subject subject = new KP_Subject();
            subject.LoadByPrimaryKey(itemResult.SubID);
            labKpName.Text = itemResult.KpName;
            labSubName.Text = itemResult.SubName;
            labBidderName.Text = subject.Bidder;
            labEndTime.Text = subject.EndDate.ToString();
            labUmpName.Text = itemResult.UmpName;

            lbtnSubmit.Enabled = !Display;
            lbtnSubmitBottom.Enabled = !Display;
            lbtnCompute.Enabled = !Display;
            lbtnComputeBottom.Enabled = !Display;

            phTemplate.Controls.Add(CreateTable(itemResult, false));


            lbtnSubmit.Attributes.Add(ConstantController.MSG_ALERT_ACTION, ConstantController.MSG_ALERT_SUBMIT_SCRIPT);
            lbtnSubmitBottom.Attributes.Add(ConstantController.MSG_ALERT_ACTION, ConstantController.MSG_ALERT_SUBMIT_SCRIPT);
        }

        // 检验合法性
        private void CheckValid()
        {
            //不能全是10也不能全是1
            bool bIsAll_10 = true;
            bool bIsAll_1 = true;
            bool bIsBetween = true;
            decimal Score = 0;

            int ItemID = 0;
            KP_Template temp = new KP_Template();

            for (int i = 0; i < Request.Form.Count; i++)
            {
                string sKeyName = Request.Form.GetKey(i);
                if (sKeyName.IndexOf(ITEM_CTRL_PREID) >= 0)
                {
                    sKeyName = sKeyName.Replace(ITEM_CTRL_PREID, "");
                    sKeyName = sKeyName.Split('_')[0];
                    ItemID = HelperDigit.ConvertToInt32(sKeyName);
                    temp.LoadByPrimaryKey(ItemID);
                    //若是数值数据则计算总分
                    if ((Request.Form[i] != null) && (temp.Item_Type == 0))
                    {
                        decimal dCurrentItemScore = HelperCurrency.GetCurrencyDecimal(Request.Form[i]);
                        //bIsAll_10 = (bIsAll_10 && dCurrentItemScore == temp.Max_Score);
                        //bIsAll_1 = (bIsAll_1 && dCurrentItemScore == temp.Min_Score);

                        bool bb = (dCurrentItemScore >= temp.Min_Score) && (dCurrentItemScore <= temp.Max_Score);
                        bIsBetween = (bIsBetween) && bb;
                        //计算总分
                        //Score += dCurrentItemScore;
                    }
                }
            }
            //判断不能是满分、不能是最低分、不能超出分值区间
            vld_Template.IsValid = bIsBetween;
        }

        // 保存结果，bIsSaved = false, 仅计算结果，不保存
        private void DoSave(bool bIsSaved)
        {
            //数据验证
            CheckValid();

            if (!Page.IsValid)
                return;

            Count();

            if (bIsSaved)
            {
                Save();
                HelperMessage.Message("保存成功");
            }
        }

        private void Save()
        {
            int nSubID = HelperURL.GetIntFromUrlString("SubID");
            int nKpID = HelperURL.GetIntFromUrlString("KpID");
            int nUmpID = HelperURL.GetIntFromUrlString("UmpID");

            VW_ZB_ItemResult vw = new VW_ZB_ItemResult();
            vw.Where.KpID.Value = nKpID;
            vw.Where.SubID.Value = nSubID;
            vw.Where.UmpID.Value = nUmpID;
            vw.Query.Load();
            while (!vw.EOF)
            {
                KP_Item_Result ir = new KP_Item_Result();
                ir.LoadByPrimaryKey(vw.ResultID);

                string ctrlID = ITEM_CTRL_PREID + vw.ItemID.ToString() + "_" + vw.TenderID;
                Control ctrl = phTemplate.FindControl(ctrlID);
                if (ctrl != null)
                {
                    TextBox tb = (TextBox)ctrl;
                    if (vw.Item_Type.Equals(0))
                    {
                        ir.Item_Score = HelperCurrency.GetCurrencyDecimal(tb.Text);
                    }
                    else
                    {
                        ir.Item_Text = tb.Text;
                    }
                    ir.Save();
                }

                vw.MoveNext();
            }
            KP_Subject_Employee se = new KP_Subject_Employee();
            se.Where.SID.Value = nSubID;
            se.Query.Load();
            while (!se.EOF)
            {
                DataRow[] items = vw.DefaultView.Table.Select("TenderID=" + se.EmployeeID);
                string sEntryID = items[0][VW_ZB_ItemResult.ColumnNames.EntryID].ToString();
                KP_Entry entry = new KP_Entry();
                if (entry.LoadByPrimaryKey(HelperDigit.ConvertToInt32(sEntryID)))
                {
                    Control ctrlTotal = phTemplate.FindControl("lb_" + ITEM_CTRL_PREID + se.EmployeeID.ToString());
                    if (ctrlTotal != null)
                    {
                        Label lb = (Label)ctrlTotal;
                        entry.Score = HelperCurrency.GetCurrencyDecimal(lb.Text);
                    }
                }
                entry.Save();

                se.MoveNext();
            }

            //修改评分专家填报状态
            KP_Subject_Table_Ump stu = new KP_Subject_Table_Ump();
            stu.Where.SubjectID.Value = nSubID;
            stu.Where.KpTableID.Value = nKpID;
            stu.Where.UmpID.Value = nUmpID;
            stu.Where.UmpType.Value = 0;
            stu.Query.Load();
            stu.Status = 1;
            stu.Save();
        }

        //计算分数
        private void Count()
        {
            int nSubID = HelperURL.GetIntFromUrlString("SubID");
            int nKpID = HelperURL.GetIntFromUrlString("KpID");
            int nUmpID = HelperURL.GetIntFromUrlString("UmpID");

            KP_Item_Result kpItemResult = new KP_Item_Result();
            KP_Template template = new KP_Template();
            VW_ZB_ItemResult vw = new VW_ZB_ItemResult();
            KP_Subject_Employee se = new KP_Subject_Employee();
            decimal dTotal = 0;

            se.Where.SID.Value = nSubID;
            se.Query.Load();
            //第一层投标人
            while (!se.EOF)
            {
                vw = new VW_ZB_ItemResult();
                vw.Where.KpID.Value = nKpID;
                vw.Where.Is_Group.Value = true;
                vw.Where.SubID.Value = nSubID;
                vw.Where.UmpID.Value = nUmpID;
                vw.Where.TenderID.Value = se.EmployeeID;
                vw.Query.Load();
                //第二层指标集
                while (!vw.EOF)
                {
                    VW_ZB_ItemResult vwItem = new VW_ZB_ItemResult();
                    decimal dGroupTotal = 0;

                    vwItem.Where.KpID.Value = nKpID;
                    vwItem.Where.Is_Group.Value = false;
                    vwItem.Where.SubID.Value = nSubID;
                    vwItem.Where.UmpID.Value = nUmpID;
                    vwItem.Where.ParentID.Value = vw.ItemID;
                    vwItem.Where.TenderID.Value = se.EmployeeID;
                    vwItem.Query.Load();

                    //第三层指标项目
                    while (!vwItem.EOF)
                    {
                        string ctrlID = ITEM_CTRL_PREID + vwItem.ItemID.ToString() + "_" + se.EmployeeID.ToString();
                        Control ctrl = phTemplate.FindControl(ctrlID);
                        if (ctrl != null)
                        {
                            TextBox tb = (TextBox)ctrl;
                            string sResult = tb.Text;
                            decimal d = 0;
                            if (vwItem.Item_Type.Equals(0))
                            {
                                d = HelperCurrency.GetCurrencyDecimal(sResult);
                            }
                            dGroupTotal += d * vwItem.Item_Quotiety;
                        }

                        vwItem.MoveNext();
                    }
                    string ctrlTotalID = ITEM_CTRL_PREID + vw.ItemID.ToString() + "_" + se.EmployeeID.ToString();
                    Control ctrlTotal = phTemplate.FindControl(ctrlTotalID);
                    if (ctrlTotal != null)
                    {
                        TextBox tbTotal = (TextBox)ctrlTotal;
                        tbTotal.Text = dGroupTotal.ToString();
                    }
                    dTotal += dGroupTotal * vw.Item_Quotiety;

                    vw.MoveNext();
                }
                string lbID = "lb_" + ITEM_CTRL_PREID + se.EmployeeID.ToString();
                Control ctrlLable = phTemplate.FindControl(lbID);
                if (ctrlLable != null)
                {
                    Label lb = (Label)ctrlLable;
                    lb.Text = dTotal.ToString("N2");
                }
                dTotal = 0;

                se.MoveNext();
            }
        }


        private void ShowScore(string nItemID, decimal dScore, bool IsLabel)
        {
            Control ctrl = phTemplate.FindControl(nItemID);
            if (ctrl != null)
            {
                if (IsLabel)
                {
                    Label lbItemScore = (Label)ctrl;
                    lbItemScore.Text = dScore.ToString("N2");
                }
                else
                {
                    TextBox txtItem = (TextBox)ctrl;
                    txtItem.Text = dScore.ToString("N2");
                }
            }
        }


        protected void lbtnSubmit_Click(object sender, System.EventArgs e)
        {
            DoSave(true);
        }

        protected void lbtnSubmitBottom_Click(object sender, System.EventArgs e)
        {
            DoSave(true);
        }

        protected void lbtnCompute_Click(object sender, System.EventArgs e)
        {
            DoSave(false);
        }

        protected void lbtnComputeBottom_Click(object sender, System.EventArgs e)
        {
            DoSave(false);
        }

        private void CountStiff()
        {
            int nSubID = HelperURL.GetIntFromUrlString("SubID");
            int nKpID = HelperURL.GetIntFromUrlString("KpID");
            int nUmpID = HelperURL.GetIntFromUrlString("UmpID");
            decimal dMaxPrice = -1;
            decimal dMinPrice = 99999999999;
            decimal dMaxScore = 0;
            decimal dMinScore = 0;

            //得到最高报价和最低有效报价
            VW_ZB_ItemResult vw = new VW_ZB_ItemResult();
            vw.Where.SubID.Value = nSubID;
            vw.Where.KpID.Value = nKpID;
            vw.Where.UmpID.Value = nUmpID;
            vw.Where.Is_Group.Value = false;
            vw.Where.Item_Type.Value = 1;
            vw.Query.Load();
            while (!vw.EOF)
            {
                TextBox tb = GetTextItem(vw.ItemID, vw.TenderID);
                decimal price = HelperCurrency.GetCurrencyDecimal(tb.Text);
                if (price > 0)
                {
                    dMaxPrice = (price > dMaxPrice) ? price : dMaxPrice;
                    dMinPrice = (price < dMinPrice) ? price : dMinPrice;
                }
                vw.MoveNext();
            }

            vw.Rewind();
            while (!vw.EOF)
            {
                TextBox tb = GetTextItem(vw.ItemID, vw.TenderID);
                decimal dPrice = HelperCurrency.GetCurrencyDecimal(tb.Text);

                VW_ZB_ItemResult s = new VW_ZB_ItemResult();
                s.Where.SubID.Value = nSubID;
                s.Where.KpID.Value = nKpID;
                s.Where.UmpID.Value = nUmpID;
                s.Where.Is_Group.Value = false;
                s.Where.Item_Type.Value = 0;
                s.Where.TenderID.Value = vw.TenderID;
                s.Query.Load();

                int ItemID = s.ResultID;
                dMaxScore = s.MaxScore;
                dMinScore = s.MinScore;

                decimal dResult = (dMaxPrice + dMinPrice - dPrice) / dMaxPrice * dMaxScore;
                dResult = (dPrice == 0) ? dMinScore : dResult;
                dResult = (dResult < dMinScore) ? dMinScore : dResult;

                tb = GetTextItem(s.ItemID, s.TenderID);
                tb.Text = dResult.ToString("N2");

                vw.MoveNext();
            }
        }

        private void CountBasePrice()
        {
            int nSubID = HelperURL.GetIntFromUrlString("SubID");
            int nKpID = HelperURL.GetIntFromUrlString("KpID");
            int nUmpID = HelperURL.GetIntFromUrlString("UmpID");
            decimal dBasePrice = 0;
            //decimal dMinPrice = 99999999999;
            decimal dMaxScore = 0;
            decimal dMinScore = 0;
            int TenderCount = 0;

            //得到基准价
            VW_ZB_ItemResult vw = new VW_ZB_ItemResult();
            vw.Where.SubID.Value = nSubID;
            vw.Where.KpID.Value = nKpID;
            vw.Where.UmpID.Value = nUmpID;
            vw.Where.Is_Group.Value = false;
            vw.Where.Item_Type.Value = 1;
            vw.Query.Load();
            while (!vw.EOF)
            {
                TextBox tb = GetTextItem(vw.ItemID, vw.TenderID);
                decimal price = HelperCurrency.GetCurrencyDecimal(tb.Text);
                if (price > 0)
                {
                    dBasePrice += price;
                    TenderCount += 1;
                }
                vw.MoveNext();
            }
            dBasePrice = (dBasePrice / TenderCount);
            dBasePrice = System.Math.Round(dBasePrice,2);
            txtBasePrice.Text = dBasePrice.ToString();
            dBasePrice = dBasePrice * HelperCurrency.GetCurrencyDecimal(txtRate.Text);
            dBasePrice = System.Math.Round(dBasePrice, 2);
            txtBaseCount.Text = dBasePrice.ToString();

            vw.Rewind();
            while (!vw.EOF)
            {
                TextBox tb = GetTextItem(vw.ItemID, vw.TenderID);
                decimal dPrice = HelperCurrency.GetCurrencyDecimal(tb.Text);
                decimal dDiff = dPrice - dBasePrice;
                decimal dAttScore = 0;
                if (dDiff>0 )
                {
                    dAttScore = HelperCurrency.GetCurrencyDecimal(txtAtt1.Text);
                }
                else
                {
                    dAttScore = HelperCurrency.GetCurrencyDecimal(txtAtt2.Text);
                    dDiff = 0 - dDiff;
                }
                //int Rate = Convert.ToInt32(Math.Round(dDiff / dBasePrice, 2) * 100);
                //Round,Ceiling,Floor 
                int Rate = (int)Math.Ceiling(dDiff / dBasePrice * 100);
                //扣分
                dAttScore = Rate * dAttScore;

                VW_ZB_ItemResult s = new VW_ZB_ItemResult();
                s.Where.SubID.Value = nSubID;
                s.Where.KpID.Value = nKpID;
                s.Where.UmpID.Value = nUmpID;
                s.Where.Is_Group.Value = false;
                s.Where.Item_Type.Value = 0;
                s.Where.TenderID.Value = vw.TenderID;
                s.Query.Load();

                int ItemID = s.ResultID;
                dMaxScore = s.MaxScore;
                dMinScore = s.MinScore;

                decimal dResult = dMaxScore - dAttScore;
                dResult = (dPrice == 0) ? dMinScore : dResult;
                dResult = (dResult < dMinScore) ? dMinScore : dResult;

                tb = GetTextItem(s.ItemID, s.TenderID);
                tb.Text = dResult.ToString("N2");

                vw.MoveNext();
            }
        }

        protected void btnAutoCount_Click(object sender, EventArgs e)
        {
            switch (dplType.SelectedValue)
            {
                case "1":
                    CountStiff();
                    break;
                case "2":
                    CountBasePrice();
                    break;
            }
            

        }

        private TextBox GetTextItem(int ItemID,int TenderID)
        {
            string ctrlID = ITEM_CTRL_PREID + ItemID + "_" + TenderID;
            TextBox tb = (TextBox)phTemplate.FindControl(ctrlID);
            if (tb == null) throw new Exception("输入框未找到");
            return tb;
        }

        private Table CreateTable(VW_ZB_ItemResult vwResult, bool IsShow)
        {
            KP_Subject_Employee se = new KP_Subject_Employee();
            ZB_Tender tender = new ZB_Tender();
            string TenderName = "";

            se.Load(vwResult.SubID);
            int nTenderCount = se.RowCount;

            //创建表头
            Table tb = new Table();
            TableRow tr = new TableRow();
            TableCell tc = new TableCell();

            //tb.Attributes.Add("style", zTable.TableStyle);
            tb.Attributes.Add("border", "1");
            //tb.Attributes.Add("class", "ms-formlabel");
            tb.Attributes.Add("width", "100%");
            tb.Attributes.Add("cellpadding", "0");
            tb.Attributes.Add("cellspacing", "0");
            tb.ID = "dtable";

            KP_Subject_Table_Ump su = new KP_Subject_Table_Ump();
            su.Where.SubjectID.Value = vwResult.SubID;
            //若是参考项目，则现示所有评分表
            if (!IsShow) su.Where.UmpID.Value = vwResult.UmpID;
            su.Where.UmpType.Value = 0;//评分
            su.Where.KpTableID.Value = vwResult.KpID;
            su.Query.Load();
            int nUmpCount = su.RowCount;

            KP_Master kpTable = new KP_Master();
            kpTable.LoadByPrimaryKey(vwResult.KpID);

            tr = new TableRow();
            tc = HelperTable.CreateStyleCell(1, 6 + nTenderCount, kpTable.Title, "font-size: 18.0pt;font-weight: 700;font-style: normal;text-decoration: none;font-family: 黑体;text-align: center;vertical-align: middle;white-space: normal;");
            tr.Cells.Add(tc);
            tb.Rows.Add(tr);

            //加入项目信息
            tr = new TableRow();
            KP_Subject subject = new KP_Subject();
            subject.LoadByPrimaryKey(vwResult.SubID);
            int nCol1 = (6 + nTenderCount) / 2;
            int nCol2 = (6 + nTenderCount) - nCol1;
            tr.Cells.Add(HelperTable.CreateStyleCell(1, nCol1, "项目名称：" + subject.SubjectName, HelperTable.ALIGN_LEFT));
            tr.Cells.Add(HelperTable.CreateStyleCell(1, nCol2, "项目编号：" + subject.Code, HelperTable.ALIGN_LEFT));
            tb.Rows.Add(tr);

            tr = new TableRow();
            tr.Cells.Add(HelperTable.CreateStyleCell(1, nCol1, "评标时间：" + DateTime.Now.ToString(), HelperTable.ALIGN_LEFT));
            tr.Cells.Add(HelperTable.CreateStyleCell(1, nCol2, "评标地点：" + subject.Address, HelperTable.ALIGN_LEFT));
            tb.Rows.Add(tr);

            tr = new TableRow();
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "序号"));
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "评议指标"));
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "指标内容"));
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "具体要求"));
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "分值"));
            tr.Cells.Add(HelperTable.CreateCell(1, nTenderCount, "投标人"));
            tr.Cells.Add(HelperTable.CreateCell(2, 1, "评分细则"));

            tb.Rows.Add(tr);

            //表头投标公司
            tr = new TableRow();

            se.Rewind();
            while (!se.EOF)
            {
                tender.LoadByPrimaryKey(se.EmployeeID);
                TenderName = tender.Name;
                tr.Cells.Add(HelperTable.CreateCell(1, 1, TenderName));

                se.MoveNext();
            }
            tb.Rows.Add(tr);


            KP_Template template = new KP_Template();
            template.Where.KP_ID.Value = vwResult.KpID;
            template.Where.Is_Group.Value = 0;
            template.Query.Load();
            int nItemCount = template.RowCount;

            template = new KP_Template();
            template.Where.KP_ID.Value = vwResult.KpID;
            template.Where.Is_Group.Value = 1;
            template.Query.Load();
            int nGroupCount = template.RowCount;

            int RowNo = 1;
            while (!su.EOF)
            {
                tr = new TableRow();
                DataRow[] drs = vwResult.DefaultView.Table.Select("UmpID=" + su.UmpID);
                string UmpName = drs[0][VW_ZB_ItemResult.ColumnNames.UmpName].ToString();

                tr.Cells.Add(HelperTable.CreateCell(nItemCount, 1, (RowNo++).ToString()));
                //评审表类型
                KP_Master master = new KP_Master();
                master.LoadByPrimaryKey(vwResult.KpID);
                KP_Category cat = new KP_Category();
                cat.LoadByPrimaryKey(master.KP_Category_ID);
                tr.Cells.Add(HelperTable.CreateCell(nItemCount, 1, cat.KP_Category_Name));

                //添加指标集
                while (!template.EOF)
                {
                    KP_Template itemTemplate = new KP_Template();
                    itemTemplate.Where.Parent_Item_ID.Value = template.Item_ID;
                    itemTemplate.Query.Load();
                    tc = HelperTable.CreateCell(itemTemplate.RowCount, 1, "");
                    //tc.Controls.Add(new LiteralControl(template.Item_Name + "(权重" + (template.Item_Quotiety * 100).ToString() + "%)"));
                    tc.Controls.Add(new LiteralControl(template.Item_Name));// + "(权重" + (template.Item_Quotiety * 100).ToString() + "%)"));
                    if (!IsShow)
                    {
                        se.Rewind();
                        while (!se.EOF)
                        {
                            tender.LoadByPrimaryKey(se.EmployeeID);
                            TenderName = tender.Name;
                            TableController.CreateScoreItem(vwResult, su.UmpID, template.Item_ID, se.EmployeeID, tc);

                            se.MoveNext();
                        }
                    }

                    //tc.Text = ;

                    tr.Cells.Add(tc);

                    //添加指标项目
                    while (!itemTemplate.EOF)
                    {
                        //                        tr.Cells.Add(HelperTable.CreateCell(1, 1, itemTemplate.Item_Name + "(权重" + (itemTemplate.Item_Quotiety * 100).ToString() + "%)"));
                        tr.Cells.Add(HelperTable.CreateCell(1, 1, itemTemplate.Item_Name));// + "(权重" + (itemTemplate.Item_Quotiety * 100).ToString() + "%)"));
                        tr.Cells.Add(HelperTable.CreateCell(1, 1, itemTemplate.Max_Score.ToString("N2")));

                        se.Rewind();
                        while (!se.EOF)
                        {
                            DataRow[] items = vwResult.DefaultView.Table.Select("UmpID=" + su.UmpID + " and ItemID= " + itemTemplate.Item_ID + " and TenderID=" + se.EmployeeID);
                            string sScore = items[0][VW_ZB_ItemResult.ColumnNames.ItemScore].ToString();
                            string sText = items[0][VW_ZB_ItemResult.ColumnNames.ItemText].ToString();
                            tc = HelperTable.CreateStyleCell(1, 1, "", HelperTable.ALIGN_RIGHT);

                            if (!IsShow)
                            {
                                TableController.CreateScoreItem(vwResult, su.UmpID, itemTemplate.Item_ID, se.EmployeeID, tc);
                            }
                            else
                            {
                                tc.Text = TableController.GetItemScore(itemTemplate.Item_Type.ToString(), sScore, sText);
                            }
                            tr.Cells.Add(tc);

                            se.MoveNext();
                        }

                        // 指标项评分描述
                        tc = HelperTable.CreateStyleCell(1, 1, itemTemplate.Item_Desc, HelperTable.ALIGN_LEFT);

                        tr.Cells.Add(tc);

                        tb.Rows.Add(tr);
                        tr = new TableRow();

                        itemTemplate.MoveNext();
                    }

                    template.MoveNext();
                }

                //表脚
                tr = new TableRow();
                tr.Cells.Add(HelperTable.CreateCell(1, 4, "总分"));
                tr.Cells.Add(HelperTable.CreateCell(1, 1, kpTable.KpScore.ToString("N2")));

                se.Rewind();
                while (!se.EOF)
                {
                    DataRow[] items = vwResult.DefaultView.Table.Select("UmpID=" + su.UmpID + " and TenderID=" + se.EmployeeID);
                    string sScore = items[0][VW_ZB_ItemResult.ColumnNames.EntryScore].ToString();
                    tc = HelperTable.CreateStyleCell(1, 1, sScore, HelperTable.ALIGN_CENTER);
                    if (!IsShow)
                    {
                        TableController.CreateTotalItem(vwResult, su.UmpID, se.EmployeeID, tc);
                    }
                    else
                    {
                        tc.Text = sScore;
                    }

                    tr.Cells.Add(tc);
                    se.MoveNext();
                }
                tr.Cells.Add(HelperTable.CreateCell(1, 1, "按权重汇总分数"));
                tb.Rows.Add(tr);

                tr = new TableRow();
                tr.Cells.Add(HelperTable.CreateStyleCell(1, 6 + nTenderCount, "评委：____________________________" + vwResult.UmpName, HelperTable.ALIGN_LEFT));
                //tr.Cells.Add(HelperTable.CreateCell(1, 6 + nTenderCount, "评委：____________________________"));
                tb.Rows.Add(tr);

                tr = new TableRow();
                tr.Cells.Add(HelperTable.CreateStyleCell(1, 6 + nTenderCount, "湖北信通通信有限公司惠达招标分公司", HelperTable.ALIGN_RIGHT));
                tb.Rows.Add(tr);

                //一个评分表创建完成;

                su.MoveNext();
            }


            return tb;
        }

        protected void dplType_SelectedIndexChanged(object sender, EventArgs e)
        {
            p.Visible = (dplType.SelectedValue == "2");
        }


    }
}
